
import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Enumeration;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author leehoa
 */
public class getMacAdd {
    
    public static void main(String are[]){
        InetAddress ip;        
        try{
		ip = InetAddress.getLocalHost();
		System.out.println("Current IP address : " + ip.getHostAddress());
		NetworkInterface network = NetworkInterface.getByInetAddress(ip);
		byte[] mac = network.getHardwareAddress();
                System.out.println("Current originate MAC address : "+new String (mac,"utf-8"));
		System.out.print("Current MAC address : "); 
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < mac.length; i++) {
			sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));		
		}
		System.out.println(sb.toString());    
        }catch(Exception ex){
        }                
        
        getMacAddress();
    }        
    
    private static void getMacAddress(){
        try{
            Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
            NetworkInterface ni = null;
            while(e.hasMoreElements())
            {
               ni = e.nextElement();
               if(ni!=null && ni.getHardwareAddress()!=null &&ni.getInetAddresses().hasMoreElements() && ni.supportsMulticast())
               {
               }
            }            
          String macAddress   = HexBin.encode(ni.getHardwareAddress());
          
          System.out.println("MACADDRESSIS"+macAddress);
        }catch(Exception ex)     {}
    }
}
    